﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace XMM.Functions
{
    public class StringManipulation
    {
        public static int getSeasonFromFileName(string sFilename)
        {
            int iSeasonNo = 0;

            Regex oExpression = new Regex(".S[0-9]+");

            string sSeasonString = oExpression.Matches(sFilename)[0].Value;

            string sSeasonNo = sSeasonString.Remove(0, 2);

            try
            {
                iSeasonNo = int.Parse(sSeasonNo);
            }
            catch (Exception ex)
            {
            }

            return iSeasonNo;
        }

        public static int getEpisodeNoFromFileName(string sFilename)
        {
            int iSeasonNo = 0;
            string sSeasonString = "0";

            Regex oExpression = new Regex("[0-9][Ee][0-9]+");

            if (oExpression.IsMatch(sFilename))
            {
                sSeasonString = oExpression.Matches(sFilename)[0].Value;

                string sSeasonNo = sSeasonString.Remove(0, 2);

                try
                {
                    iSeasonNo = int.Parse(sSeasonNo);
                }
                catch (Exception ex)
                {
                }
            }

            return iSeasonNo;
        }
    }
}
